
import {ref} from 'vue'
import store from '@/store'

// 列表页搜索时的地区列表
export const useSearchAreaList = (callback) => {
    store.dispatch('proxyAction', {
        name: 'manageInstitutionAreas',
        queries: {},
        message: false
    }).then((res) => {
        callback(format(res.data))

    }).catch(err => {
        store.dispatch('message', {
            message: err.message || '请求失败'
        });
    })
}
const format = function(data){
    return data.map(item => {
        if(item.subAreas && item.subAreas.length){
            item.subAreas = format(item.subAreas)
        }
        return {
            label: item.areaName,
            value: item.areaId,
            children: item.subAreas
        }
    })
}